
#include "../include/_PLL_SOGI.h"

#include <vector>
#include <list>
#include <iostream>
//#include <tuple>
//#include <utility>
#include <cmath>

#ifdef _win64系统
#include <windows.h>
#else
#include <ctime>
#endif

using namespace std;

#define π 3.141592653589793238462643383279

#define 步长 100 //us
#define 周期 20 //ms
#define 周期数 50


int main()
{   

    // std::vector<float> theta;
    // std::vector<float> A;
    // std::vector<float> f;
    const int 点数 = 周期*1000*周期数/步长;
    float theta[点数];        
    float A[点数];    
    float f[点数];
    float usin[点数];
    void *p1 = PLL_SOGI_Creat();
    void *p2 = PLL_SOGI_Creat();
    for (int i=0 ; i<点数; i ++){
        usin[i] = 100*cos( i*2*π/(周期*1000.0/(double)步长)  );
    }

#ifdef _win64系统
    LARGE_INTEGER t1, t2, tc;
    QueryPerformanceFrequency(&tc);
    QueryPerformanceCounter(&t1);
#else
    clock_t time_start = clock();
#endif

    for (int i=0 ; i<点数; i ++){
        //auto usin = sin( i*2*π/(周期*1000.0/(double)步长)  );
        float ttheta,tA,tf;
        PLL_SOGI_Cal(
            (PLL_SOGI*)p1,
            usin[i],
                     55,
                     94,
                     3658,
                     2 * π * 50,
                     -2 * π * 50,
                     0.01,
                     36.16,
                     1.45,
                     0.123,
                     (float)步长/1e6,
                     &ttheta,
                     &tA,
                     &tf ,
                     0  );
        theta[i] = ttheta;
        A[i] = tA;
        f[i] = tf;
    }

#ifdef _win64系统
    QueryPerformanceCounter(&t2);
    auto time = (double)(t2.QuadPart - t1.QuadPart) / (double)tc.QuadPart;
    cout << "点数：" << 点数 <<endl;
    cout << "time =  " << 1000.0 * time << "  ms" << endl; //输出时间（单位：ｓ）
    cout << endl;
    cout << endl;
#else
    clock_t time_end = clock();
    cout << "点数：" << 点数 <<endl;
    cout << "time =  " << 1000.0 * (time_end - time_start) / (double)CLOCKS_PER_SEC << "  ms" << endl; //输出时间（单位：ｓ）
    cout << endl;
    cout << endl;    
#endif

    for(int i=点数*0.9 ; i<点数; i ++){
        cout<< "输入：  "<<usin[i]<<"  相位：  "<<theta[i]<<"   幅值：   "<<A[i]<<"   频率：   "<<f[i]<<endl;
    }
    
    

    system("pause");

}
